﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Threading;

namespace MarkdownExplorer
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        internal const string FileNameKey = "FileName";

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (e.Args != null && e.Args.Count() > 0)
            {
                Properties[FileNameKey] = e.Args[0];
            }
            else
            {
                // Check if this was launched by double-clicking a doc. If so, use that as the
                // startup file name.
                var activationArguments = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;

                if (activationArguments != null
                    && activationArguments.ActivationData != null
                    && activationArguments.ActivationData.Length > 0)
                {
                    string fileName = String.Empty;

                    fileName = AppDomain.CurrentDomain.SetupInformation
                                .ActivationArguments.ActivationData[0];

                    // It comes in as a URI; this helps to convert it to a path.
                    Uri uri = new Uri(fileName);
                    fileName = uri.LocalPath;

                    Properties[FileNameKey] = fileName;
                }
            }
        }
    }
}